"""
医疗费用个人数据集中，"身体质量指数BMI"与"个人医疗费用"两者之间的关系

数据集原地址：https://www.kaggle.com/mirichoi0218/insurance/home
"""
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Scatter

# 1.读取保险费数据集
df = pd.read_csv('./Files/insurance/insurance.csv')
print(df.head())
print()
print(df.info())

# 2.pyecharts绘制散点图
df.sort_values(by="bmi", inplace=True)  # 对bmi列进行升序排序
bmi = df["bmi"].to_list()
charges = df["charges"].to_list()

# 3.绘制散点图
scatter = (
    Scatter()
    .add_xaxis(
        xaxis_data=bmi
    )
    .add_yaxis(
        series_name="",
        y_axis=charges,
        symbol_size=4,
        label_opts=opts.LabelOpts(is_show=False)
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="(BMI-保险费)关系图", pos_left="center"),
        xaxis_opts=opts.AxisOpts(type_="value"),
        yaxis_opts=opts.AxisOpts(type_="value")
    )
)

scatter.render('./Files/my_Scatter.html')
